<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子19-ES6/7常用语法介绍</title>
    </head>
    <body>
        <pre>
            <code>
                // 例子19

                const fn = x => x + 5;
                // 等同于
                //let fn = function(x) {
                //	return x + 5;
                //}

                //--------------------------------------------------------------------------

                const add = (x, y) => x + y;
                // 等同于
                //let add = function(x, y) {
                //	return x + y;
                //}

                //--------------------------------------------------------------------------

                const divide = (x, y) => {
                    if (typeof x === 'number' && typeof y === 'number' && y !== 0 && !isNaN(x) && !isNaN(y)) {
                        let result = Math.floor(x / y);
                        let mod = x % y;
                        return `${x}除以${y}的商为${result}，余数为${mod}。`
                    } else {
                        return '输入不合法';
                    }
                }
                divide(1, 2); // "1除以2的商为0，余数为1。"

                //--------------------------------------------------------------------------

                [1, 2, 3].map((value, key) => (`key is ${key} and value is ${value}`)).join('\n');
                // "key is 0 and value is 1
                // key is 1 and value is 2
                // key is 2 and value is 3"
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/19.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>